package com.wlk.controller;

import com.wlk.pojo.Project;
import com.wlk.pojo.dto.AddProDTO;
import com.wlk.service.ProjectService;
import com.wlk.utils.Result;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/project")
public class ProjectController {
    @Resource
    private ProjectService projectService;

    /**
     * @description: 添加新项目
     * @author:
     * @date: 2024/6/17 下午2:30
     * @param:
     * @return:
     **/
    @PostMapping("/add")
    public Result add(@RequestBody AddProDTO addProDTO) {
       return projectService.addPro(addProDTO);
    }
    /**
     * @description: 获取项目列表用于管理
     * @author:
     * @date: 2024/6/17 下午2:31
     * @param:
     * @return:
     **/
    @GetMapping("/list")
    public Result getProList() {
        return projectService.getProList();
    }

    /**
     * @description: 根据用户的id获取该id拥有的项目权限，用于供选择填报项目
     * @author:
     * @date: 2024/6/18 下午3:29
     * @param:
     * @return:
     **/
    @GetMapping("/getGrantedProByUserId/{userId}")
    public Result getGrantedProByUserId(@PathVariable("userId") Integer userId) {
        return projectService.getGrantedProByUserId(userId);
    }

    /**
     * @description: getProListByHeaderId 根据headerId获取该headerId的项目列表（用于分权）
     * @author:
     * @date: 2024/6/18 下午10:03
     * @param:
     * @return:
     **/
    @GetMapping("/getProListByHeaderId/{headerId}")
    public Result getProListByHeaderId(@PathVariable("headerId") Integer headerId) {
        return projectService.getProListByHeaderId(headerId);
    }

    /**
     * @description: 删除项目
     * @author:
     * @date: 2024/6/19 下午10:34
     * @param:
     * @return:
     **/
    @DeleteMapping("/delete/{proCpde}")
    public Result delProByProCode(@PathVariable("proCpde") String proCode) {
        return projectService.delProByProCode(proCode);
    }
}
